home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / Extensions… / Additions ƒ / PrintDialogMessage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-14  |  10.2 KB  |  349 lines  |  [TEXT/MPS ]

  1. /* ------------------------------------------------------------------------------
  2.  
  3.     FILENAME
  4.         PrintDialogMessage.c
  5.  
  6.     DESCRIPTION
  7.         This file contains the message procedure that will be invoked when the Printing Manager
  8.         issues the PrintDialog message.  The routine which is called is PrintDlgMessageProc.
  9.         This routine calls SetUpAdditionsDlgPanel to add the Additions dialog panel to the
  10.         Print Dialog and to define the routines to call in order to process item hits and 
  11.         events in the panel.
  12.         
  13.         The Additions panel utilizes an the Print Dialog's 'xdtl' capability to automatically
  14.         check/uncheck the buttons in the dialog.  It does, however, also provide an event filter
  15.         procedure (PanelFilterMessageProc) and an item hit procedure (PanelEventMessageProc) for performing
  16.         actions above and beyond those provided by the 'xdtl' facility.
  17.  
  18.     COPYRIGHT
  19.         Copyright Apple Computer, Inc. 1991 - 1996
  20.         All rights reserved. 
  21.     
  22.     INTERFACE ROUTINES
  23.         PrintDlgMessageProc
  24.  
  25.     MODIFICATION HISTORY
  26.         05/15/91            ALA                Initial Implementation
  27.         06/15/93            Sam Weiss        GetMyResFile -> GetMessageHandlerResFile
  28.          6/14/96            cn                    Updated to support Universal Interfaces 2.1.
  29.         
  30.  
  31.  
  32. ------------------------------------------------------------------------------- */
  33.  
  34. #include <Types.h>
  35. #include <Quickdraw.h>
  36. #include <Memory.h>
  37. #include <Resources.h>
  38. #include <Dialogs.h>
  39. #include <TextEdit.h>
  40. #include <OSUtils.h>
  41. #include <Packages.h>
  42. #include <ToolUtils.h>
  43. #include <Menus.h>
  44. #include <String.h>
  45. #include <Strings.h>
  46. #include <Printing.h>
  47.  
  48. #include <GXGraphics.h>
  49. #include <GraphicsLibraries.h>
  50. #include <FontLibrary.h>
  51.  
  52. #include <Collections.h>
  53. #include <GXMessages.h>
  54.  
  55. #include    <GXPrinting.h>
  56.  
  57. #include "Utilities.h"
  58. #include "Additions.h"
  59.  
  60.  
  61. /*==================================== CONSTANTS ====================================*/
  62.  
  63.  
  64. /* ===== Dialog 'ppnl' related constants ===== */
  65.  
  66. #define    kAdditionsPanelResID            gxPrintingExtensionBaseID        /* Resource ID of the Addition's 'ppnl' resource */
  67.  
  68.  
  69. /* ===== Dialog panel 'DITL' constants ===== */
  70.  
  71. #define    diAddPageBorder        2        /* Add page border to each page item */
  72. #define    diSerializeCopies        3        /* Serialize all printed copies item */
  73. #define    diAddCoverPage            4        /* Add a cover page item */
  74. #define    diCoverPageFirst        5        /*     Add cover page at beginning item */
  75. #define    diCoverPageLast        6        /*     Add cover page at end item */
  76. #define    diStartCopynum            7        /* Starting copy number for serialization */
  77.  
  78.  
  79. /* ===== Dialog panel 'ICN#' constants ===== */
  80.  
  81. #define    kCoverPageOnTop        gxPrintingExtensionBaseID            /* Cover page icon with the cover page on top */
  82. #define    kCoverPageOnBott        gxPrintingExtensionBaseID + 1    /* Cover page icon with the cover page on bottom */
  83.  
  84.  
  85. /*================================ INTERNAL ROUTINES ================================*/
  86.  
  87.  
  88. /* ===== OpenAdditionsPanel ===== 
  89.  
  90.     Processes the panel dialog Open message for the extension's panel.  It assumes a SetPort
  91.     has already been performed.
  92. */
  93. void OpenAdditionsPanel(        //    (out)    Error code
  94.     DialogPtr        pDlg,            //    (in)    Pointer to the Print dialog
  95.     short                itemCount)    //    (in)    Number of ditl items before our panel's dialog items
  96. {
  97.     Boolean    coverPageOn;
  98.     
  99.     /* Enable/disable the cover page radio buttons depending upon whether Cover Page is checked */
  100.     
  101.     coverPageOn = CheckBoxIsOn(pDlg, itemCount + diAddCoverPage);
  102.     EnableControlOnOff(pDlg, itemCount + diCoverPageFirst, coverPageOn);
  103.     EnableControlOnOff(pDlg, itemCount + diCoverPageLast, coverPageOn);
  104.  
  105.     /* Force the Cover Page icons to be drawn */
  106.     {
  107.         short        itemType;
  108.         Rect        itemRect;
  109.         Handle    hItem;
  110.  
  111.         GetDItem(pDlg, itemCount + diCoverPageFirst, &itemType, &hItem, &itemRect);
  112.         itemRect.top -= 8;
  113.         itemRect.bottom += 8;
  114.         itemRect.left = itemRect.right;
  115.         itemRect.right = itemRect.left + 32;
  116.         InvalRect(&itemRect);
  117.  
  118.         GetDItem(pDlg, itemCount + diCoverPageLast, &itemType, &hItem, &itemRect);
  119.         itemRect.top -= 8;
  120.         itemRect.bottom += 8;
  121.         itemRect.left = itemRect.right;
  122.         itemRect.right = itemRect.left + 32;
  123.         InvalRect(&itemRect);
  124.     }
  125. }
  126. /* OpenAdditionsPanel */
  127.  
  128.  
  129. /* ===== PanelFilterMessageProc ===== 
  130.  
  131.     Processes the panel dialog Filter event message for the extension's panel.
  132. */
  133.  
  134. OSErr PanelFilterMessageProc(
  135.     gxPanelInfoRecord    *panelInfo,        /*    (in)    Pointer to the Print panel info. */
  136.     Boolean                *weDidEvent)    /*    (out)    true => panel processed the event; false => Printing Manager should handle it */
  137. {
  138. #pragma unused ( unused )
  139.  
  140.  
  141.     *weDidEvent = false;
  142.     
  143.     if (panelInfo->theEvent->what == updateEvt)    /* T => May draw the cover page icons */
  144.     {
  145.         /* Only draw the icons if it's our window */
  146.         if ( panelInfo->pDlg == (DialogPtr) panelInfo->theEvent->message )
  147.         {
  148.             short        itemType;
  149.             Rect        itemRect;
  150.             Handle    hItem;
  151.             Handle    theIcon;
  152.             
  153.             GetDItem(panelInfo->pDlg, panelInfo->itemCount + diCoverPageFirst, &itemType, &hItem, &itemRect);
  154.             itemRect.top -= 8;
  155.             itemRect.bottom += 8;
  156.             itemRect.left = itemRect.right + 1;
  157.             itemRect.right = itemRect.left + 32;
  158.             
  159.             theIcon = GetIcon(kCoverPageOnTop);
  160.             if (theIcon != nil)
  161.             {
  162.                 PlotIcon(&itemRect, theIcon);
  163.                 ReleaseResource(theIcon);
  164.             }
  165.             
  166.             GetDItem(panelInfo->pDlg, panelInfo->itemCount + diCoverPageLast, &itemType, &hItem, &itemRect);
  167.             itemRect.top -= 8;
  168.             itemRect.bottom += 8;
  169.             itemRect.left = itemRect.right + 1;
  170.             itemRect.right = itemRect.left + 32;
  171.  
  172.             theIcon = GetIcon(kCoverPageOnBott);
  173.             if (theIcon != nil)
  174.             {
  175.                 PlotIcon(&itemRect, theIcon);
  176.                 ReleaseResource(theIcon);
  177.             }
  178.         }
  179.     }
  180.     /* else - some other type of event */
  181.     
  182.     return(*weDidEvent);
  183. }
  184. /* PanelFilterMessageProc */
  185.  
  186.  
  187. /* ===== PanelEventMessageProc ===== 
  188.  
  189.     Processes the panel dialog ItemHit message for the extension's panel.  Note that we rely
  190.     on the 'xdtl' capability of the Print Dialog to save the new settings in the 
  191.     Additions collection item (this is why the routine doesn't process the kPanelConfirmEvt
  192.     message.
  193. */
  194. OSErr PanelEventMessageProc(                /*    (out)    special Print panel error code */
  195.     gxPanelInfoRecord        *panelInfo,        /*    (in)    Pointer to the Print panel info. */
  196.     gxPanelResult *unused)
  197. {
  198.  
  199. #pragma unused ( unused )
  200.  
  201.     OSErr            anErr = noErr;
  202.     GrafPtr        oldPort;
  203.     DialogPtr    pDlg;
  204.     
  205.     pDlg = panelInfo->pDlg;
  206.     
  207.     GetPort(&oldPort);
  208.     SetPort(pDlg);
  209.     
  210.     /* Determine the type of hit message we received */
  211.     switch (panelInfo->panelEvt)
  212.     {
  213.         case gxPanelOpenEvt:
  214.             OpenAdditionsPanel(pDlg, panelInfo->itemCount);
  215.             break;
  216.             
  217.         case gxPanelHitEvt:
  218.         {
  219.             short        whichItem;
  220.  
  221.             /* If the cover page check box was clicked, enable the cover page radio buttons */
  222.         
  223.             whichItem = panelInfo->itemHit - panelInfo->itemCount;
  224.             if ( whichItem == diAddCoverPage )
  225.             {
  226.                 Boolean    radiosEnabled;
  227.                 
  228.                 radiosEnabled = CheckBoxIsOn(pDlg, panelInfo->itemHit);
  229.                 
  230.                 EnableControlOnOff(pDlg, panelInfo->itemCount + diCoverPageFirst, radiosEnabled);
  231.                 EnableControlOnOff(pDlg, panelInfo->itemCount + diCoverPageLast, radiosEnabled);
  232.             }
  233.             break;
  234.         }
  235.         
  236.         case gxPanelActivateEvt:
  237.         case gxPanelDeactivateEvt:
  238.         case gxPanelIconFocusEvt:
  239.         case gxPanelPanelFocusEvt:
  240.         {
  241.             /* Activate/deactivate the serial number edit text field if it's the current edit text field */
  242.             if ( (((DialogPeek) pDlg)->editField + 1) == (panelInfo->itemCount + diStartCopynum) )
  243.             {
  244.                 if (    (panelInfo->panelEvt == gxPanelIconFocusEvt)        ||
  245.                         (panelInfo->panelEvt == gxPanelDeactivateEvt)
  246.                     )                                                        // T => Deactivate the TE field
  247.                     TEDeactivate(((DialogPeek) pDlg)->textH);
  248.                 else
  249.                     TEActivate(((DialogPeek) pDlg)->textH);
  250.             }
  251.             break;
  252.         }
  253.     }
  254.     
  255.     SetPort(oldPort);
  256.     
  257.     return(anErr);
  258. }
  259. /* DoJobPanelItemHit */
  260.  
  261.  
  262. /* ===== SetUpAdditionsDlgPanel =====
  263.  
  264.     SetUpAdditionsDlgPanel adds the Additions dialog panel to the Print dialog.
  265. */
  266. OSErr SetUpAdditionsDlgPanel(        //    (out)    error code
  267.     gxJob        printJob,                //    (in)    the Job reference for the job we're printing
  268.     short        additionsResFile)        //    (in)    refnum of the Additions file
  269. {
  270.     OSErr                                anErr = noErr;
  271.     Collection                        jobCollection;
  272.     gxPanelSetupRecord            thePanelInfo;
  273.     AdditionsCollection            additionsConfig;
  274.     
  275.     /* Get a reference to the job's collection */
  276.     jobCollection = GXGetJobCollection(printJob);
  277.     
  278.     /* See if the Addition's collection item exists.  If the item already exists, then */
  279.     /* we'll use the last settings. */
  280.     anErr = GetCollectionItem (jobCollection,
  281.                                            kAdditionsCollectionType,
  282.                                            gxPrintingTagID,
  283.                                            nil,
  284.                                            &additionsConfig);
  285.     
  286.     if (anErr == collectionItemNotFoundErr)    // T => Item doesn't exist; add it
  287.     {
  288.         /* Initialize what will be the initial dialog settings */
  289.         additionsConfig.nextEndSerialNum        = 1;
  290.         additionsConfig.coverPage                = kCoverPageFirst;
  291.         additionsConfig.addPageBorder            = false;
  292.         additionsConfig.serializeCopies        = false;
  293.         additionsConfig.addCoverPage            = false;
  294.         
  295.         /* Add the Additions collection item */
  296.         anErr = AddCollectionItem(    jobCollection,
  297.                                             kAdditionsCollectionType,
  298.                                             gxPrintingTagID,
  299.                                             sizeof(AdditionsCollection),
  300.                                             &additionsConfig);
  301.     }
  302.     
  303.     if (anErr == noErr)
  304.     {
  305.         /* Initialize the dialog panel structure */
  306.         thePanelInfo.panelResId            = kAdditionsPanelResID;
  307.         thePanelInfo.resourceRefNum    = additionsResFile;
  308.         thePanelInfo.refCon                = 0;
  309.         thePanelInfo.panelKind            = gxExtensionPanel;
  310.         
  311.         /* Add the dialog panel to the Print dialog */
  312.         anErr = GXSetupDialogPanel(&thePanelInfo);
  313.     }
  314.     
  315.     return(anErr);
  316. }
  317. /* SetUpAdditionsDlgPanel */
  318.  
  319.  
  320. /*================================== MESSAGE INTERFACE ROUTINE ==================================*/
  321.  
  322.  
  323. /* ===== PrintDlgMessageProc =====
  324.  
  325.     PrintDlgMessageProc is the extension's routine which will be invoked when Printing issues a 
  326.     PrintDialog message.  This routine will call SetUpAdditionsDlgPanel to add a dialog panel to the
  327.     Print dialog.  The user can use that panel to select the additive effects to be added
  328.     to the document pages.  The effects selected are recorded in a AdditionsCollection record and
  329.     stored with the Job collection.  At despooling and rendering time, this configuration is retrieved and 
  330.     the page filtered based upon the configuration's settings.
  331. */
  332. OSErr PrintDlgMessageProc(        //    (out)    Error code
  333.     gxDialogResult    *result)
  334. {
  335.     
  336.     OSErr     anErr;
  337.     
  338.     /* Add the Filter's panel to the Print dialog */
  339.     anErr = SetUpAdditionsDlgPanel(GXGetJob(), GXGetMessageHandlerResFile());
  340.     if (anErr == noErr)
  341.     {
  342.         /* Pass the PrintDialog message on to others */
  343.         anErr = Forward_GXJobPrintDialog(result);
  344.     }
  345.     
  346.     return(anErr);
  347. }
  348. /* PrintDlgMessageProc */
  349.